/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* IBust - IBus with Traditional interface
 * Copyright(c) 2013 Daniel Sun
 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
 * Copyright (C) 2008-2010 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#if !defined (__IBUST_H_INSIDE__) && !defined (IBUST_COMPILATION)
#error "Only <ibust.h> can be included directly"
#endif

/**
 * SECTION: ibustobject
 * @short_description: Base object of IBust.
 * @title: IBustObject
 * @stability: Stable
 *
 * IBustObject is the base object for all objects in IBust.
 */
#ifndef __IBUST_OBJECT_H_
#define __IBUST_OBJECT_H_

#include <glib-object.h>
#include "ibusttypes.h"
#include "ibustdebug.h"

/*
 * Type macros.
 */

/* define GOBJECT macros */
#define IBUST_TYPE_OBJECT             \
    (ibust_object_get_type ())
#define IBUST_OBJECT(obj)             \
    (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUST_TYPE_OBJECT, IBustObject))
#define IBUST_OBJECT_CLASS(klass)     \
    (G_TYPE_CHECK_CLASS_CAST ((klass), IBUST_TYPE_OBJECT, IBustObjectClass))
#define IBUST_IS_OBJECT(obj)          \
    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUST_TYPE_OBJECT))
#define IBUST_IS_OBJECT_CLASS(klass)  \
    (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUST_TYPE_OBJECT))
#define IBUST_OBJECT_GET_CLASS(obj)   \
    (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUST_TYPE_OBJECT, IBustObjectClass))

typedef enum {
    IBUST_IN_DESTRUCTION = (1 << 0),
    IBUST_DESTROYED      = (1 << 1),
    IBUST_RESERVED_1     = (1 << 2),
    IBUST_RESERVED_2     = (1 << 3),
} IBustObjectFlags;

#define IBUST_OBJECT_FLAGS(obj)             (IBUST_OBJECT (obj)->flags)
#define IBUST_OBJECT_SET_FLAGS(obj,flag)    G_STMT_START{ (IBUST_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
#define IBUST_OBJECT_UNSET_FLAGS(obj,flag)  G_STMT_START{ (IBUST_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END
#define IBUST_OBJECT_IN_DESTRUCTION(obj)    (IBUST_OBJECT_FLAGS (obj) & IBUST_IN_DESTRUCTION)
#define IBUST_OBJECT_DESTROYED(obj)         (IBUST_OBJECT_FLAGS (obj) & IBUST_DESTROYED)

G_BEGIN_DECLS

typedef struct _IBustObject IBustObject;
typedef struct _IBustObjectClass IBustObjectClass;
typedef struct _IBustObjectPrivate IBustObjectPrivate;

/**
 * IBustObject:
 *
 * All the fields in the <structname>IBustObject</structname> structure are
 * private to the #IBustObject and should never be accessed directly.
 */
struct _IBustObject {
    GInitiallyUnowned parent;
    /* instance members */
    guint32 flags;

    IBustObjectPrivate *priv;
};

typedef void ( *IBustObjectDestroyFunc) (IBustObject *);

struct _IBustObjectClass {
    GInitiallyUnownedClass parent;

    /* signals */
    void (* destroy)        (IBustObject   *object);

    /*< private >*/
    /* padding */
    gpointer pdummy[7];
};

GType           ibust_object_get_type            (void);

/**
 * ibust_object_new:
 * @returns: A newly allocated IBustObject
 *
 * New an IBustObject.
 */
IBustObject     *ibust_object_new                 (void);

/**
 * ibust_object_destroy:
 * @object: an #IBustObject to destroy.
 *
 * Emit the "destory" signal notifying all reference holders that they should
 * release the #IBustObject.
 *
 * The memory for the object itself won't be deleted until its reference count
 * actually drops to 0; ibust_object_destroy merely asks reference holders to
 * release their references. It does not free the object.
 */
void            ibust_object_destroy             (IBustObject     *object);

G_END_DECLS
#endif

